<template>
	<view class="h-[calc(100vh-45px)] py-1 px-3 flex flex-col justify-between">
		<!-- 核单打包 -->
		<view>
			<uv-form labelPosition="left" labelWidth="auto">
				<uv-form-item label="单号" prop="getForm.trackingNumber">
					<uv-input v-model="getForm.trackingNumber" border="none" placeholder="请输入或扫描订单号" />
					<uv-button type="primary" shape="circle" @click="getData">查询</uv-button>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="h-[calc(100%-110px)]">
			<uni-table border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center">快递单号</uni-th>
					<uni-th align="center">快递名</uni-th>
					<uni-th align="center">快递类型</uni-th>
					<uni-th align="center">会员id</uni-th>
					<uni-th align="center">会员名称</uni-th>
					<uni-th align="center">订单号</uni-th>
					<uni-th align="center">重量</uni-th>
					<uni-th align="center">存放区域</uni-th>
					<uni-th align="center">状态</uni-th>
					<uni-th align="center">单件价值</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-th align="center">{{ item.courierNumber }}</uni-th>
					<uni-th align="center">{{ item.cargoName }}</uni-th>
					<uni-th align="center">{{ item.cargoType }}</uni-th>
					<uni-th align="center">{{ item.userId }}</uni-th>
					<uni-th align="center">{{ item.userName }}</uni-th>
					<uni-th align="center">{{ item.courierNumber }}</uni-th>
					<uni-th align="center">{{ item.weight }}</uni-th>
					<uni-th align="center">{{ item.seat }}</uni-th>					
					<uni-th align="center">{{ statusName[item.status] }}</uni-th>
					<uni-th align="center">{{ item.singleValue }}</uni-th>
				</uni-tr>
			</uni-table>
		</view>
		<uv-button type="success" shape="circle" @click="vouchingPick">打包</uv-button>
	</view>
</template>

<script setup>
	import { getInspectOrder, setInspectOrder } from '@/api/modules/inspectOrder.js'
	
	const statusName = ['签收', '入库', '上架', '用户已支付', '拣货', '核重', '装袋', '打单', '装车']
	const getForm = ref({
		trackingNumber: ''
	}) // 订单号查询
	const selectionArr = ref([]) // 多选内容集合
	const tableData = ref([]) // 表格数据

	// 查询单号
	const getData = async () => {
		const res = await getInspectOrder(getForm.value)
		if (res.code === 200) {
			tableData.value.push(res.data)
		}
		console.log(res)
	}
	
	// 打包
	const vouchingPick = () => {
		console.log(selectionArr.value)
		const trackingNumber = selectionArr.value.map(item => {
			return tableData.value[item].courierNumber
		})
		console.log(trackingNumber)
		setInspectOrder(trackingNumber).then(res => {
			setTimeout(() => {
				uni.navigateTo({ url: '/pages/index/index' })
			}, 2000)
		}).catch(err => {
			console.log(err)
		})
	}
	
	// 多选内容发生变化
	const selectionChange = (e) => {
		selectionArr.value = e.detail.index
	}
</script>

<style>

</style>
